package com.wingsfrog.puzzle.controller;

import com.wingsfrog.puzzle.controller.dto.response.BaseResDto;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@ControllerAdvice
public class GlobalExceptionController {
    Logger logger = Logger.getLogger(GlobalExceptionController.class);
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object doException(Exception e,HttpServletResponse response){
        e.printStackTrace();
        logger.error(e.getMessage());
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return new BaseResDto(-1,e.getMessage());
    }
}
